package o;

import android.content.Context;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.downloadengine.api.SplitTask;
import com.huawei.appgallery.foundation.application.pkgmanage.model.update.ApkUpgradeInfo;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse.LayoutData;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailHiddenBean;
import com.huawei.appmarket.service.appdetail.view.card.DetailHiddenCard;
import com.huawei.appmarket.service.distribution.authentication.bean.AgdSecurityVerificationResponse;
import com.huawei.appmarket.service.distribution.thirddistribution.bean.LayoutDataMini;
import com.huawei.appmarket.service.webview.base.jssdk.control.FullAppStatus;
import com.huawei.hms.framework.common.ContainerUtils;
import java.util.ArrayList;
import java.util.List;

public class dxq {

    public interface c {
        void ˎ(@Nullable SessionDownloadTask sessionDownloadTask);
    }

    public static void ˊ(@NonNull AgdSecurityVerificationResponse agdSecurityVerificationResponse) {
        List arrayList = new ArrayList();
        List ᐝॱ = agdSecurityVerificationResponse.ᐝॱ();
        if (!CollectCheck.isEmpty(ᐝॱ)) {
            for (int i = 0; i < ᐝॱ.size(); i++) {
                LayoutDataMini layoutDataMini = new LayoutDataMini();
                layoutDataMini.ˊ(((LayoutData) ᐝॱ.get(i)).ˋ());
                layoutDataMini.ˋ(((LayoutData) ᐝॱ.get(i)).ˎ());
                layoutDataMini.ॱ(((LayoutData) ᐝॱ.get(i)).ˏ());
                arrayList.add(layoutDataMini);
            }
            agdSecurityVerificationResponse.ˏ(arrayList);
        }
    }

    public static void ˏ(@NonNull AgdSecurityVerificationResponse agdSecurityVerificationResponse) {
        List ˏ = agdSecurityVerificationResponse.ˏ();
        if (!CollectCheck.isEmpty(ˏ)) {
            List ᐝॱ = agdSecurityVerificationResponse.ᐝॱ();
            for (int i = 0; i < ˏ.size(); i++) {
                LayoutDataMini layoutDataMini = (LayoutDataMini) ˏ.get(i);
                List ʽ = layoutDataMini.ʽ();
                long ˎ = layoutDataMini.ˎ();
                for (int i2 = 0; i2 < ᐝॱ.size(); i2++) {
                    LayoutData layoutData = (LayoutData) ᐝॱ.get(i2);
                    if (layoutData.ˎ() == ˎ) {
                        layoutData.ॱ(ʽ);
                    }
                }
            }
        }
    }

    @Nullable
    public static DetailHiddenBean ॱ(@NonNull AgdSecurityVerificationResponse agdSecurityVerificationResponse) {
        List ᐝॱ = agdSecurityVerificationResponse.ᐝॱ();
        if (CollectCheck.isEmpty(ᐝॱ)) {
            Logger.ˎ("DistributionUtil", "download info is null!");
            return null;
        }
        for (int i = 0; i < ᐝॱ.size(); i++) {
            LayoutData layoutData = (LayoutData) ᐝॱ.get(i);
            Object ˏ = layoutData.ˏ();
            if (!TextUtils.isEmpty(ˏ) && (drp.ˎ(ˏ) instanceof DetailHiddenCard)) {
                List ˋ = layoutData.ˋ();
                if (!CollectCheck.isEmpty(ˋ) && (ˋ.get(0) instanceof DetailHiddenBean)) {
                    return (DetailHiddenBean) ˋ.get(0);
                }
            }
        }
        return null;
    }

    public static SessionDownloadTask ॱ(@NonNull DetailHiddenBean detailHiddenBean) {
        SessionDownloadTask ˏ = new dqw().ˏ(dqw.ˊ(detailHiddenBean.ॱـ(), detailHiddenBean.ॱᶥ(), detailHiddenBean.ˎˎ()));
        if (ˏ == null) {
            return null;
        }
        ˊ(ˏ, detailHiddenBean);
        return ˏ;
    }

    public static void ˏ(@NonNull final DetailHiddenBean detailHiddenBean, final c cVar) {
        new dqw().ˏ(dqw.ˊ(detailHiddenBean.ॱـ(), detailHiddenBean.ॱᶥ(), detailHiddenBean.ˎˎ()), new o.dqw.c() {
            public void ˋ(SessionDownloadTask sessionDownloadTask) {
                if (sessionDownloadTask != null) {
                    dxq.ˊ(sessionDownloadTask, detailHiddenBean);
                } else {
                    Logger.e("DistributionUtil", "getDownloadTask sessionDownloadTask null.");
                }
                if (cVar != null) {
                    cVar.ˎ(sessionDownloadTask);
                }
            }

            public void ॱ() {
                Logger.e("DistributionUtil", "getDownloadTask get bundle info fail.");
                if (cVar != null) {
                    cVar.ˎ(null);
                }
            }
        });
    }

    private static void ˊ(SessionDownloadTask sessionDownloadTask, @NonNull DetailHiddenBean detailHiddenBean) {
        int parseInt;
        if (detailHiddenBean.ॱᶥ() == 0) {
            SplitTask splitTask = new SplitTask();
            splitTask.ˋ(detailHiddenBean.ʾ());
            splitTask.ˊ(detailHiddenBean.ʼॱ());
            splitTask.ˊॱ(detailHiddenBean.ॱـ());
            splitTask.ˋ(detailHiddenBean.ˉ());
            sessionDownloadTask.ˏ(splitTask);
        }
        sessionDownloadTask.ˊ(detailHiddenBean.ʾ());
        sessionDownloadTask.ॱॱ(detailHiddenBean.v_());
        sessionDownloadTask.ʼ(detailHiddenBean.ॱـ());
        sessionDownloadTask.ॱ(detailHiddenBean.ͺˏ());
        sessionDownloadTask.ʽ(detailHiddenBean.ॱˌ());
        sessionDownloadTask.ˏ(detailHiddenBean.ॱॱ());
        sessionDownloadTask.ᐝ(detailHiddenBean.u_());
        sessionDownloadTask.ˊ(ccz.ॱ());
        sessionDownloadTask.ˎ(detailHiddenBean.ᐝᐝ());
        sessionDownloadTask.ॱ(detailHiddenBean.ˏॱ());
        sessionDownloadTask.ॱˊ(detailHiddenBean.ॱᶥ());
        try {
            parseInt = Integer.parseInt(detailHiddenBean.ˎˎ());
        } catch (NumberFormatException e) {
            Logger.e("DistributionUtil", "version code error " + e.toString());
            parseInt = 0;
        }
        sessionDownloadTask.ʻ(parseInt);
        sessionDownloadTask.ˎ(detailHiddenBean.ॱʼ());
        ApkUpgradeInfo ॱ = dug.ॱ(detailHiddenBean.ॱـ());
        if (ॱ != null && ॱ.ʿ() >= parseInt) {
            List ᐝˊ = sessionDownloadTask.ᐝˊ();
            if (!CollectCheck.isEmpty(ᐝˊ)) {
                splitTask = (SplitTask) ᐝˊ.get(0);
                if (ॱ.ʼ() > 0) {
                    splitTask.ॱ(ॱ.ʼ());
                    splitTask.ˏ(ॱ.ॱॱ());
                    splitTask.ˎ(ॱ.ˈ());
                    splitTask.ˋ(ॱ.ʽॱ());
                }
                sessionDownloadTask.ˊ(ॱ.ʽॱ());
            }
            sessionDownloadTask.ˏ(ॱ.ˊᐝ());
            sessionDownloadTask.ॱ(ॱ.ˏˎ());
        }
        if (detailHiddenBean.ᐝˊ() != null) {
            sessionDownloadTask.ॱˊ("trackId=" + dof.ˎ(detailHiddenBean.ᐝˊ()));
        }
        sessionDownloadTask.ॱˊ("familyShare=" + detailHiddenBean.ᐝ());
    }

    public static boolean ˋ(@NonNull AgdSecurityVerificationResponse agdSecurityVerificationResponse) {
        drr o_drr = new drr();
        drr.ˊ(o_drr, new cfv(), agdSecurityVerificationResponse);
        return (o_drr.ˋ() == null || o_drr.ᐝ() == null || CollectCheck.isEmpty(o_drr.ʽ())) ? false : true;
    }

    public static String ˊ(@NonNull dxn o_dxn) {
        StringBuilder stringBuilder = new StringBuilder();
        if (!TextUtils.isEmpty(o_dxn.ˏ())) {
            stringBuilder.append("mediaPkg=").append(o_dxn.ˏ()).append(ContainerUtils.FIELD_DELIMITER);
        }
        if (!TextUtils.isEmpty(o_dxn.ʻ())) {
            stringBuilder.append("referrer=").append(dof.ˎ(o_dxn.ʻ())).append(ContainerUtils.FIELD_DELIMITER);
        }
        if (!TextUtils.isEmpty(o_dxn.ᐝ())) {
            stringBuilder.append("advInfo=").append(o_dxn.ᐝ()).append(ContainerUtils.FIELD_DELIMITER);
        }
        stringBuilder.append("advPlatform=").append(o_dxn.ˎ()).append(ContainerUtils.FIELD_DELIMITER);
        stringBuilder.append("contentId=").append(o_dxn.ॱ()).append(ContainerUtils.FIELD_DELIMITER);
        stringBuilder.append("callerPkg=").append(o_dxn.ˊ()).append(ContainerUtils.FIELD_DELIMITER);
        stringBuilder.append("downloadFlags=").append(o_dxn.ॱॱ());
        return stringBuilder.toString();
    }

    public static void ˎ(SessionDownloadTask sessionDownloadTask, Context context) {
        FullAppStatus fullAppStatus = new FullAppStatus();
        fullAppStatus.ˊ(sessionDownloadTask.ˊˊ());
        fullAppStatus.ˏ(3);
        fullAppStatus.ˊ(sessionDownloadTask.ʼॱ());
        fullAppStatus.appType_ = 2;
        fullAppStatus.callerPkg_ = sessionDownloadTask.ॱˎ("callerPkg");
        fullAppStatus.contentId_ = sessionDownloadTask.ॱˎ("contentId");
        fullAppStatus.mediaPkg_ = sessionDownloadTask.ॱˎ("mediaPkg");
        fullAppStatus.extendDownloadFlags_ = sessionDownloadTask.ॱˎ("downloadFlags");
        dzd.ॱ(context).ॱ(fullAppStatus);
    }
}
